using SS;
using System;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.sys
{
	public class frmResetData : Form
	{
		private IContainer components = null;
		private Button btnClose;
		private Button btnReset;
		private Func objFunc = new Func();
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.btnClose = new Button();
			this.btnReset = new Button();
			base.SuspendLayout();
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(187, 8);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(94, 30);
			this.btnClose.TabIndex = 13;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.btnReset.Cursor = Cursors.Hand;
			this.btnReset.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnReset.Location = new Point(12, 8);
			this.btnReset.Name = "btnReset";
			this.btnReset.Size = new Size(169, 30);
			this.btnReset.TabIndex = 14;
			this.btnReset.Text = "Khởi tạo dữ liệu từ đầu";
			this.btnReset.UseVisualStyleBackColor = true;
			this.btnReset.Click += new EventHandler(this.btnReset_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(292, 46);
			base.ControlBox = false;
			base.Controls.Add(this.btnReset);
			base.Controls.Add(this.btnClose);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			this.MaximumSize = new Size(308, 80);
			this.MinimumSize = new Size(308, 80);
			base.Name = "frmResetData";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: KHỞI TẠO DỮ LIỆU";
			base.Load += new EventHandler(this.frmResetData_Load);
			base.ResumeLayout(false);
		}
		public frmResetData()
		{
			this.InitializeComponent();
		}
		private void btnReset_Click(object sender, EventArgs e)
		{
			if (MessageBox.Show("Bạn chắc chắn muốn khởi tạo lại dữ liệu không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
			{
				try
				{
					string value = string.Concat(new string[]
					{
						Application.ExecutablePath.ToUpper().Replace("TVSGPP.EXE", ""),
						"TVSGPP-BK-",
						DateTime.Now.Day.ToString(),
						"-",
						DateTime.Now.Month.ToString(),
						"-",
						DateTime.Now.Year.ToString()
					});
					SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
					sqlConnection.Open();
					SqlCommand sqlCommand = new SqlCommand("doBackup", sqlConnection);
					sqlCommand.CommandType = CommandType.StoredProcedure;
					sqlCommand.Parameters.Add("databaseName", SqlDbType.VarChar, 250);
					sqlCommand.Parameters.Add("databasePath", SqlDbType.VarChar, 500);
					sqlCommand.Parameters["databaseName"].Value = ConfigurationSettings.AppSettings["DataBase"].ToString();
					sqlCommand.Parameters["databasePath"].Value = value;
					try
					{
						sqlCommand.ExecuteNonQuery();
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
					}
					new SqlCommand("sp_resetData", sqlConnection)
					{
						CommandType = CommandType.StoredProcedure
					}.ExecuteNonQuery();
					sqlConnection.Close();
					sqlConnection.Dispose();
					base.Close();
				}
				catch
				{
				}
			}
		}
		private void frmResetData_Load(object sender, EventArgs e)
		{
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
	}
}
